#include "my_inc/main_login.h"

static int get(int (*data)[FOUR])
{
    for (int i = 0; i < FOUR; i++)
    {
        int a = 0;
        while (!a)
        {
            a = 1;
            for (int j = 0; j < 3; j++)
            {
                if (data[j][i] == 0 && data[j + 1][i] != 0)
                {
                    data[j][i] = data[j + 1][i];
                    data[j + 1][i] = 0;
                    a = 0;
                }
            }
        }
    }
}

int up(int (*data)[FOUR], int (*temp)[FOUR])
{
    get(data);
    for (int i = 0; i < FOUR; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (data[j][i] == data[j + 1][i] && data[j][i] != 0)
            {
                data[j][i] = 2 * data[j][i];
                data[j + 1][i] = 0;
            }
        }
    }
    get(data);
    int x = estimate(data, temp);
    if (!x)
    {
        if (!get_config())
        {

            printf("您输了!  请按ESC键退出游戏!!!\n");
            return 0;
        }

        printf("错误的移动!\n");
        return 2;
    }
    int over = write_2048(data);

    if (!estchess(data) && !write_2048(data))
    {
        // printf("您输了!  5s后退出游戏!\n");
        printf("您输了!  请按ESC键退出游戏!!!\n");
        set_config(0); 
        return 0;
    }
    return 1;
}